<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/admin/AdminAction.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/Response.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/Service.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/ServiceFactory.php';

final class PersonEditAction extends AdminAction {
	protected function execute(Response $response) {
		$personIdentity = null;
		if(isset($_SESSION['person-identity'])) {
			$personIdentity = $_SESSION['person-identity'];
			unset($_SESSION['person-identity']);
		}
		if(isset($_POST['identity'])) {
			$personIdentity = $_POST['identity'];
		}
		if($personIdentity !== null) {
			$serviceFactory = new ServiceFactory();
			$personService = $serviceFactory->getService('PersonService');
			$person = $personService->read($personIdentity);
			$response->setParameter('person', $person);
			$postService = $serviceFactory->getService('PostService');
			$freePosts = $postService->getFreePosts($person);
			$response->setParameter('free-posts', $freePosts);
			$roles = $personService->getRoles();
			$response->setParameter('roles', $roles);
		}
	}
}
?>